<style scoped>
    .pro-con {
        padding: 0 20px;
        margin-bottom: 50px;
    }

    .pro-con .ivu-form-item {
        margin-bottom: 0;
    }

    .pro-con .ivu-col {
        padding-right: 0 !important;

    }

    .fr {
        float: right;
    }

    .pro-pagesize .mr10 {
        margin-right: 10px;
    }

    .search-h3 {
        font-size: 18px;
        color: #ef8412;
        font-weight: normal;
        margin-bottom: 20px;
    }


    /*//////////////////////////////*/

    .search-h3 {
        font-size: 18px;
        color: #ef8412;
        font-weight: normal;
        margin-bottom: 20px;
    }

    .search-form {
        border-bottom: 1px solid #d9d9d9;
    }

    .search-form .ivu-col {
        margin-bottom: 15px;
    }

    .clear {
        clear: both;
    }

    .table-theme {
        clear: both;
    }

    .table-action {
        padding-top: 0;
        padding-bottom: 15px;
    }

    .pro-pagesize {
        margin-bottom: 10px;

    }

    .common-box-body.pr0 .ivu-form-item {
        padding-right: 0 !important;
    }
</style>
<template>
    <div class="pro-list">
        <product-title></product-title>
        <div class="pro-con">
            <div class="pro-con-f common-box-body">
                <h3 class="search-h3 huang">
                    快速搜索
                </h3>
                <Row class="">
                    <Form :model="searchForm">
                        <Col :xs="24" :sm="24" :md="12" :lg="6">
                        <Form-item label="日期">
                            <DatePicker type="month" transfer placeholder="请选择日期" v-model="searchForm.old_dateTime" @on-change="datachange($event,searchForm,'dateTime')" :options="options3"></DatePicker>
                        </Form-item>
                        </Col>
                        <Col :xs="24" :sm="24" :md="12" :lg="6">
                        <Form-item label="机构">
                            <Select v-model="searchForm.yun_org_mid" transfer placeholder='请选择机构'>
                                <Option value="0">全部</Option>
                                <Option :value="item.id" v-for="item in allJG" :key="item.id">{{item.shortn}}</Option>
                            </Select>
                        </Form-item>
                        </Col>
                        <Col :xs="24" :sm="24" :md="12" :lg="6">
                        <Form-item label="员工工号">
                            <Input placeholder="请输入工号" v-model="searchForm.jobCode"></Input>
                        </Form-item>
                        </Col>
                         <Col :xs="24" :sm="24" :md="12" :lg="6">
                        <Form-item label="员工姓名">
                            <Input placeholder="请输入员工姓名" v-model="searchForm.name"></Input>
                        </Form-item>
                        </Col>
                        <Col :xs="24" :sm="24" :md="12" :lg="6">
                        <Form-item label="当前职级">
                            <Select v-model="searchForm.rank_id" transfer placeholder='请选择职级'>
                                <Option value="0">全部</Option>
                                <Option :value="item.id" v-for="item in rankList" :key="item.id">{{item.name}}</Option>
                            </Select>
                        </Form-item>
                        </Col>
                        <Col :xs="24" :sm="24" :md="24" :lg="24" class="table-action">
                            <Button type="primary" size="large" class="fr mr10" @click="jisuan">计算</Button>  
                        </Col>
                    </Form>
                    <div class="clear"></div>
                </Row>

            </div>
            <div class="table-theme highlight_table">
                <Table ref="currentRowTable" @on-current-change="tableCurrentChange($event)" size="large" stripe
                    border :columns="header" :data="list"></Table>
            </div>
            <div id="footer">
                <Row class="pro-pagesize">
                    <Col :md="24" :lg="24" class="tRight">
                    <Page ref="pages" :total="classTotal" show-total show-sizer :current="p" show-elevator :page-size="pagesize" @on-change="pageChange"
                        @on-page-size-change="pageSizeChange" placement="top" class="page"></Page>
                    </Col>
                </Row>
            </div>
        </div>
    </div>
</template>

<script>
    import productTitle from '../../components/productTitle.vue'
    import util from '../../libs/util'
    import {getListByName} from '../../api/basiclaw'
    export default {
        data() {
            return {
                options3:{
                    disabledDate (date) {
                        return date.valueOf() > Date.now() - 86400000;
                    }
                },
                rankList: [],
                total: 0,
                header: [{
                        type: 'index',
                        title: '序号',
                        width: '60',
                        align: 'center'
                    },
                    {
                        key: 'jobCode',
                        title: '员工工号',
                        align: 'center'
                    },
                    {
                        key: 'employyeName',
                        title: '员工姓名',
                        align: 'center'
                    },
                    {
                        key: 'employyeLevel',
                        title: '当前职级',
                        align: 'center'
                    },
                    {
                        key:'up',
                        title: '晋升结果',
                        align: 'center',

                        render:(h,params)=>{
                            let str="";
                            let style={};
                            if(params.row.up){
                                str="晋升成功"
                                style={
                                    color:"green"
                                }
                            }else{
                                 str="晋升失败";
                                 style={
                                    color:"red"
                                }
                            }
                            return h('div',{
                                style:style
                            },str);
                        }
                    },
                    {
                        key: 'down',
                        title: '维持结果',
                        align: 'center',
                        render:(h,params)=>{
                            let str="";
                            let style="";
                            if(params.row.down){
                                str="维持成功";
                                 style={
                                    color:"green"
                                }
                            }else{
                                 str="维持失败";
                                  style={
                                    color:"red"
                                }
                            }
                            return h('div',{
                                 style:style
                            },str);
                        }
                    },
                ],
                p: 1,
                pagesize: 10,
                list: [],
                current: {},
                classTotal: 0,
                searchForm: {
                    dateTime: '',
                    old_dateTime: '',
                    p: 1,
                    pagesize: 10,
                    name: "",
                    jobCode:'',
                    yun_org_mid:'',
                    cid:'',
                },
                allJG:[]
            }
        },
        components: {
            productTitle
        },
        created() {
            let date = new Date().toLocaleDateString().split('/');
            //对当前年月日进行判断  如果大于26，显示前一个月，反之显示当月，当 当前月份为1月时，显示为上一年12月
            // if (date[2] < 26) {
            //     if (date[1] == 1) {
            //         date[1] = 12;
            //         date[0] = date[0] - 1;
            //     } else {
            //         date[1] = date[1] - 1;
            //     }
            // }
            date[1] = date[1] < 10 ? "0" + date[1] : date[1];
            this.searchForm.old_dateTime = date[0] + "-" + date[1];
            this.searchForm.dateTime = date[0] + "-" + date[1];
            this.getjg();
            this.getRank();
        },
        activated() {

        },
        methods: {
            pageChange(val) {
                this.p = val;
                this.jisuan();
            },
            pageSizeChange(val) {
                this.pagesize = val;
                this.jisuan();
            },
            jisuan(){
                this.searchForm.p=this.p;
                this.searchForm.pagesize=this.pagesize;
                new Promise(()=>{
                    // let url="http://192.168.0.11:8180/kb/v1/rule/assess/excuteAll/";
                    let url=BASE_URL1+"/kb/v1/rule/assess/excuteAll";
                    util.ajax.get(url,{
                        params:this.searchForm
                    }).then(res=>{
                        if(res.data.err==0){
                            this.tableloading = false;
                            this.list=res.data.data.returnList;
                            this.classTotal=res.data.data.count;
                            this.$Message.success('操作成功');
                        }else{
                            this.$Message.error(res.data.info);
                        }
                    }).catch(error=>{
                        this.$Message.error('搜索失败');
                    })
                })
            },
            //获取机构
            getjg(){
                new Promise((resolve, reject) => {
                    getListByName().then(response => {
                        if (response.data.err == 0) {
                            this.allJG = response.data.data;
                        } else {
                            this.$Message.error(response.data.info);
                        }
                        resolve();
                    }).catch(error => {
                        reject(error);
                    });
                });
            },
            getRank(){
                new Promise(()=>{
                    // let url="http://192.168.0.11:8180/kb/v1/rank/all";
                    let url=BASE_URL1+"/kb/v1/rank/all/";
                    util.ajax.get(url).then(res=>{
                        if(res.data.code==0){
                            // console.log(res.data.data);
                            this.rankList = res.data.data.dataList;
                        }else{
                            this.$Message.error(res.data.info);
                        }
                        
                    })
                })
            },
             datachange(date, obj, attr) {
                obj[attr] = date;
            },
        }
    }
</script>